<?php

//	Author: 	Christos Polydorou
//	Email:		std04237@di.uoa.gr
//	Purpose: 	Get an entity

require_once ("../DB/DB.php");
require_once ("../Frameworks/Objects/user.php");
require_once ("../Frameworks/Objects/category.php");
require_once ("../Frameworks/Objects/entity.php");


function DB_getEntity($entityid)
{

    global $conn;

    // The name of the stored procedure
    $sp_name = "usp_getEntity";

    // The return variable
    $retval;

    // Create a new statement
    $stmt = mssql_init($sp_name, $conn);

    // Bind values
    mssql_bind($stmt, "RETVAL", $retval, SQLINT4, true, false, 1);
    mssql_bind($stmt, '@entityid', $entityid, SQLINT4, false, false, 1);

    // Execute the statement
    $status = mssql_execute($stmt);
    if ($status)
    {
        $entity = new Entity();
        $entity->SetId($entityid);
        $i = '0';
        $attributes = array();
         /* the table with the attributes of the category */
        while ($row = mssql_fetch_row($status))
        {
            $entity->SetName($row[0]);
            //				$entity->SetIsApproved[$row[4]);
            $entity->SetCategoryId($row[3]);
            $attribute = new Attribute();
            $attribute->SetName($row[1]);
            $attribute->SetValue($row[2]);
            $attribute->SetCategoryId($row[3]);
            $attribute->SetType($row[5]);
            $attribute->SetBestValue($row[6]);
            $attribute->SetId($row[7]);
            $attributes[$i] = $attribute;
            $i++;
            mssql_next_result($status);
        }
        $entity->SetAttributes($attributes);
        return $entity;
    }
}

?>